<!DOCTYPE html>
<html>

<head>
  <title>横向轮播图</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    .wrapper {
      position: absolute;
      top: 50px;
      width: 100%;
      height: 200px;
      display: flex;
      justify-content: center;
      align-items: center;
      transform-style: preserve-3d;
      perspective: 800px;
    }

    .wrapper .img-box {
      position: absolute;
      width: 400px;
      height: 150px;
    }

    .wrapper .img-box img {
      position: absolute;
      width: 400px;
      height: 150px;
      border-radius: 10px;
      box-shadow: 5px 5px 5px #ccc;
      transition: all 0.5s;
    }

    .wrapper ul {
      position: absolute;
      bottom: 0;
    }

    .wrapper ul li {
      display: inline-block;
      width: 15px;
      height: 15px;
      border-radius: 50%;
      background-color: #ccc;
    }
  </style>
</head>

<body>
  <div class="wrapper">
    <div class="img-box">
      <img src="./img/1.jpg" alt="">
      <img src="./img/2.jpg" alt="">
      <img src="./img/3.jpg" alt="">
      <img src="./img/4.jpg" alt="">
      <img src="./img/5.jpg" alt="">
    </div>
    <ul>
      <li></li>
      <li></li>
      <li></li>
      <li></li>
      <li></li>
    </ul>
  </div>
</body>
<script src="./js/jquery-1.8.3.min.js"></script>
<script>
  var displayIndex = 2;
  var timer = 0;
  var zLevel = 100;
  var yLevel = 100;
  var imgs = $('.wrapper .img-box img');
  var lis = $('.wrapper ul li');

  function init() {
    show();
    bindEvent();
  }
  init();
  function show() {
    //修改图片样式
    var leftIndex,
        rightIndex,
        halfNum = Math.floor(imgs.length / 2);
    //当前图片
    imgs.eq(displayIndex).css({
      transform: 'translateZ(0px)', left: '0px',
        zIndex: 900 
      });

    for (var i = 0; i < halfNum; i++) {
      //左侧图片
      leftIndex = displayIndex - i -1;
      imgs.eq(leftIndex).css({
        transform: 'translateZ(' + (-(i + 1) * zLevel) + 'px)', left: (-(i + 1) * yLevel) + 'px',
        zIndex: 900 + (-(i + 1) * zLevel),
      });
      //右侧图片
      rightIndex = displayIndex + i + 1;
      if(rightIndex >= imgs.length){
        rightIndex -= imgs.length;
      }
      imgs.eq(rightIndex).css({
        transform: 'translateZ(' + (-(i + 1) * zLevel) + 'px)', left: ((i + 1) * yLevel) + 'px',
        zIndex: 900 + (-(i + 1) * zLevel),
      });
    }
    //修改 li 样式
    for(var i = 0; i < lis.length; i++){
      lis.eq(i).css({
        backgroundColor: '#ccc'
      });
    }
    lis.eq(displayIndex).css({
      backgroundColor: 'red'
    });

  }
  function bindEvent() {
    imgs.on('click', function () {
      displayIndex = $(this).index();
      console.log('img click', displayIndex);
      show();
    });
    lis.live('click', function () {
      displayIndex = $(this).index();
      console.log('li live click', displayIndex);
      show();
    });
    $('.wrapper').hover(function () {
      clearInterval(timer);
    }, function () {
      timer = setInterval(play, 2000);
    });
    timer = setInterval(play, 2000);
  }

  function play() {
    displayIndex++;
    if (displayIndex > $('.wrapper .img-box img').length - 1) {
      displayIndex = 0;
    }
    show();
  }

</script>
</html>